<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Laporans extends CI_Controller {

    var $kasus_id;
    var $santri_id;
    var $tanggal_mulai;
    var $tanggal_selesai;
    var $status;
    var $cari;
    var $message;

    function __construct() {
        parent::__construct();
        $this->load->library('auth');
        $this->auth->restrict();

        $this->load->helper(array('text', 'url'));
        $this->load->model(array('m_kasus', 'm_santri', 'm_kat_kasus', 'm_sub_kasus', 'm_izin'));
        $uri = $this->uri->uri_to_assoc(3);

        if (isset($uri['id'])) {
            $this->kasus_id = $uri['id'];
        }

        if (isset($uri['status'])) {
            $this->status = $uri['status'];
        }

        if (isset($_POST['in_cari'])) {
            $this->cari = $this->input->post('in_cari');
            $this->session->set_userdata('cari', $this->cari);
        }

        if ($this->session->userdata('cari')) {
            $this->cari = $this->session->userdata('cari');
        }

        if ($this->auth->cek_role_member() != '1') {
            redirect('homes');
        }

        if (isset($_POST['in_santri'])) {
            $this->santri_id = $this->input->post('in_santri');
        }

        if (isset($_POST['in_tanggal_mulai']) && isset($_POST['in_tanggal_selesai'])) {
            $this->tanggal_mulai = $this->input->post('in_tanggal_mulai');
            $this->tanggal_selesai = $this->input->post('in_tanggal_selesai');
            $this->session->set_userdata('tgl_mulai', $this->tanggal_mulai);
            $this->session->set_userdata('tgl_selesai', $this->tanggal_selesai);
        }

        if (isset($_POST['in_tanggal_keluar']) && isset($_POST['in_tanggal_masuk'])) {
            $this->tanggal_mulai = $this->input->post('in_tanggal_keluar');
            $this->tanggal_selesai = $this->input->post('in_tanggal_masuk');
            $this->session->set_userdata('tgl_mulai', $this->tanggal_mulai);
            $this->session->set_userdata('tgl_selesai', $this->tanggal_selesai);
        }
    }

    public function index() {
        redirect('homes/', 'refresh');
    }

    public function laporan_per_santri() {
        $santris = $this->m_santri->get_kategori_menu();

        $data['title'] = $this->lang->line('menu_lap_per_santri') . ' ' . $this->lang->line('webname');
        $data['santris'] = $santris;

        $this->load->view('view_header', $data);
        $this->load->view('report_per_santri', $data);
        $this->load->view('view_footer_kasus', $data);
    }

    public function laporan_per_santri_popup() {
        $atts = array(
            'width' => '800',
            'height' => '600',
            'scrollbars' => 'yes',
            'status' => 'yes',
            'resizable' => 'yes',
            'screenx' => '0',
            'screeny' => '0'
        );

        echo anchor_popup(base_url() . 'index.php/laporans/laporan_per_santri_pdf', 'Click Me!', $atts);
    }

    public function laporan_per_santri_pdf() {
        $this->load->library('cezpdf');
        $this->load->helper('pdf');

        $db_data = $this->m_kasus->get_kasus_by_santri_id($this->santri_id);
        $col_names = array(
            'kasus_id' => 'No',
            'kasus_tanggal' => 'Tanggal',
            'kasus_santri' => 'Santri',
            'kasus_kat_kasus' => 'Kategori Kasus',
            'kasus_sub_kat_kasus' => 'Subab Kasus',
            'kasus_keterangan' => 'Keterangan',
            'kasus_oleh' => 'Musaid'
                //'kasus_dirubah' => 'kasus_dirubah'
        );

        $title = 'Daftar Kasus Per Santri : ' . $this->m_santri->get_by_id($this->santri_id)->santri_nama;

        $this->cezpdf = new Cezpdf('a4', 'landscape', 'none');
        prep_pdf();
        $this->cezpdf->ezTable($db_data, $col_names, $title, array('width' => 820));
        $this->cezpdf->ezStream();
    }

    public function laporan_per_tanggal() {
        $santris = $this->m_santri->get_kategori_menu();

        $data['title'] = $this->lang->line('menu_lap_per_tanggal') . ' ' . $this->lang->line('webname');
        $data['santris'] = $santris;

        $this->load->view('view_header', $data);
        $this->load->view('report_per_tanggal', $data);
        $this->load->view('view_footer', $data);
    }

    public function laporan_per_tanggal_pdf() {
        $this->load->library('cezpdf');
        $this->load->helper('pdf');

        $db_data = $this->m_kasus->get_kasus_by_santri_tgl($this->tanggal_mulai, $this->tanggal_selesai);
        $col_names = array(
            'kasus_id' => 'No',
            'kasus_tanggal' => 'Tanggal',
            'kasus_santri' => 'Santri',
            'kasus_kat_kasus' => 'Kategori Kasus',
            'kasus_sub_kat_kasus' => 'Subab Kasus',
            'kasus_keterangan' => 'Keterangan',
            'kasus_oleh' => 'Musaid'
                //'kasus_dirubah' => 'kasus_dirubah'
        );

        $title = 'Daftar Kasus Per Tanggal : ' . 'Dari ' . $this->tanggal_mulai . ' Sampai ' . $this->tanggal_selesai;


        $this->cezpdf = new Cezpdf('a4', 'landscape', 'none');
        prep_pdf();
        $this->cezpdf->ezTable($db_data, $col_names, $title, array('width' => 820));
        $this->cezpdf->ezStream();
    }

    public function laporan_izin_per_santri() {
        $santris = $this->m_santri->get_kategori_menu();

        $data['title'] = $this->lang->line('menu_lap_per_santri') . ' ' . $this->lang->line('webname');
        $data['santris'] = $santris;

        $this->load->view('view_header', $data);
        $this->load->view('report_izin_per_santri', $data);
        $this->load->view('view_footer_kasus', $data);
    }

    public function laporan_izin_per_santri_pdf() {
        $this->load->library('cezpdf');
        $this->load->helper('pdf');

        $db_data = $this->m_izin->get_izin_by_santri_id($this->santri_id);
        $col_names = array(
            'izin_id' => 'No',
            'izin_santri' => 'Santri',
            'izin_keluar' => 'Tanggal keluar',
            'izin_masuk' => 'Tanggal keluar',
            'izin_keperluan' => 'Keperluan',
            'izin_oleh' => 'Musaid'
                //'kasus_dirubah' => 'kasus_dirubah'
        );

        $title = 'Daftar Izin Per Santri : ' . $this->m_santri->get_by_id($this->santri_id)->santri_nama;

        $this->cezpdf = new Cezpdf('a4', 'landscape', 'none');
        prep_pdf();
        $this->cezpdf->ezTable($db_data, $col_names, $title, array('width' => 820));
        $this->cezpdf->ezStream();
    }

    public function laporan_izin_per_tanggal() {
        $santris = $this->m_santri->get_kategori_menu();

        $data['title'] = $this->lang->line('menu_lap_izin_per_tanggal') . ' ' . $this->lang->line('webname');
        $data['santris'] = $santris;

        $this->load->view('view_header', $data);
        $this->load->view('report_izin_per_tanggal', $data);
        $this->load->view('view_footer_izin', $data);
    }

    public function laporan_izin_per_tanggal_pdf() {
        $this->load->library('cezpdf');
        $this->load->helper('pdf');

        //echo $this->tanggal_mulai . " = " . $this->tanggal_selesai . "<br />";

        $db_data = $this->m_izin->get_izin_by_santri_tgl($this->tanggal_mulai, $this->tanggal_selesai);
        $col_names = array(
            'izin_id' => 'No',
            'izin_keluar' => 'Tanggal Keluar',
            'izin_masuk' => 'Tanggal Masuk',
            'izin_santri' => 'Santri',
            'izin_keperluan' => 'Keperluan',
            'izin_oleh' => 'Musaid'
                //'kasus_dirubah' => 'kasus_dirubah'
        );

        $title = 'Daftar Izin Per Tanggal : ' . 'Dari ' . $this->tanggal_mulai . ' Sampai ' . $this->tanggal_selesai;


        $this->cezpdf = new Cezpdf('a4', 'landscape', 'none');
        prep_pdf();
        $this->cezpdf->ezTable($db_data, $col_names, $title, array('width' => 820));
        $this->cezpdf->ezStream();
    }

    public function xxx() {
        $this->load->library('cezpdf');
        $this->load->helper('pdf');

        //prep_pdf('landscape'); // creates the footer for the document we are creating.

        $db_data = $this->m_kasus->get_kasus_by_santri_id(1);
        $col_names = array(
            'kasus_id' => 'No',
            'kasus_tanggal' => 'Tanggal',
            'kasus_santri' => 'Santri',
            'kasus_kat_kasus' => 'Kategori Kasus',
            'kasus_sub_kat_kasus' => 'Subab Kasus',
            'kasus_keterangan' => 'Keterangan',
            'kasus_oleh' => 'Musaid'
                //'kasus_dirubah' => 'kasus_dirubah'
        );

        $this->cezpdf = new Cezpdf('a4', 'landscape', 'none');
        $this->cezpdf->ezTable($db_data, $col_names, 'Daftar Kasus Santri', array('width' => 820));
        $this->cezpdf->ezStream();
    }

}

/* End of file laporans.php */
/* Location: ./application/controllers/laporans.php */